<template>
  <dialog-editor ref="dialog" :fullscreen="true"></dialog-editor>
</template>

<script>
  import DialogEditor from '@/components/DialogEditor'
  import dialogMixins from '@/utils/commonDialogMixins'
  import {mRequest} from '@/utils/request'
  export default {
    mixins: [dialogMixins],
    components: {DialogEditor},
    data() {
      return {
        dataFormConfig: {
          id: {
            hidden: true
          },
          weighDetailNo: {
            label: '记录单号',
            placeholder: '记录单号',
            disabled: true
          },
          type: {
            label: '类型',
            type: 'radio',
            radioBorder: false,
            radioList: [
              {text: '销售', label: 0},
              {text: '采购', label: 2}
            ],
            default: 0
          },
          planOrderId: {
            default: [],
            label: '产品出库编号',
            placeholder: '请选择产品出库编号',
            selectMultiple: true,
            type: 'list',
        //    reply: () => !this.R.equals(2, this.dataForm['type']),
            list: []
          },
          sysDictId: {
            default: [],
            label: '产品名称',
            placeholder: '请输入产品名称',
            type: 'list',
            list: [],
          //  reply: () => !this.R.equals(0, this.dataForm['type']),
          },
          grossWeight: {
            label: '毛重',
            type: 'number',
            placeholder: '请输入毛重',
            selectCallback: this.weightSelectCallback
          },
          tareWeight: {
            label: '皮重',
            type: 'number',
            placeholder: '请输入皮重',
            selectCallback: this.weightSelectCallback
          },
          netWeight: {
            label: '净重',
            type: 'number',
            placeholder: '请输入净重'
          },
          buckleWeight: {
            label: '扣重',
            type: 'number',
            placeholder: '请输入扣重'
          },

          supplierId: {
            label: '供货单位',
            type: 'list',
            list: [],
            placeholder: '请输入供货单位',
            reply: () => this.R.equals(2, this.dataForm['type']),
          },
          licensePlateId: {
            label: '车辆信息',
            placeholder: '请输入车辆信息',
            type: 'list',
            list: [],
          },
          driverId: {
            label: "驾驶员",
            placeholder: '请输入车辆信息',
            type: 'list',
            list: []
          },
          entranceTime: {
            label: '入场时间',
            type: 'date',
            placeholder: '请输入入场时间'
          },
          leaveTime: {
            label: '出场时间',
            type: 'date',
            placeholder: '请输入出场时间'
          },
          // clientId:{
          //   label: '客户',
          //   selectMultiple: true,
          //   placeholder: '请选择客户',
          //   type: 'list',
          //   list: [],
          // },
          freightPaymentMethod: {
            label: '运费支付方式',
            type: 'radio',
            radioBorder: false,
            radioList: [
              {text: '本厂自付', label: 0},
              {text: '客户代付', label: 1},
              {text: '客户自付', label: 2},
              {text: '其他', label: 3},
            ],
            default: 0
          },
          freightSettlementStatus: {
            label: '运费结算方式',
            type: 'radio',
            radioBorder: false,
            radioList: [
              {text: '未付款', label: 0},
              {text: '已付款', label: 1},
            ],
            default: 0
          },
          remark: {
            label: '备注',
            inputType: 'textarea',
            placeholder: '请输入备注'
          },
          status: {
            label: '状态',
            type: 'switch',
            activeValue: 1,
            inactiveValue: 0,
            default: 1
          }
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
       // this.initProductInfoList()
      //  this.initClientInfoList()
         this.initSupplierIdList()
         this.initDriveInfoList()
         this.initPlanOrderIdList()
         this.initLicensePlateInfoList()
         this.initIngredientInfoList('sysDictId')

        this.$refs.dialog.initDialog({
          dataForm: this.dataForm,
          config: this.dataFormConfig,
          dataRule: this.getNeedDataRule( 'status','entranceTime','driverId','planOrderId','sysDictId'),
          initApi: 'weighApi/weighDetailInfoInfo',
          saveApi: 'weighApi/saveWeighDetailInfo',
          updateApi: 'weighApi/updateWeighDetailInfo',
          objectName: 'weighDetailInfo'
        })
      },
      orderSelectHandle(orderId, cb) {
        if (this.R.isNil(orderId) || this.R.isEmpty(orderId)) {
          return
        }
        mRequest('planApi/planOrderInfoInfo', {id: orderId}, ({data}) => {
          if (!(cb instanceof Function)) {
            return
          }
          return cb(data)
        })
      },
      orderSelectCallback(){
        this.orderSelectHandle(this.dataForm.planOrderId, (data) => {
       /*   this.dataForm['sysDictId'] = this.R.pathOr(0, ['planOrderInfo', 'sysDictId'], data)
          this.dataForm['clientId'] = this.R.pathOr(0, ['planOrderInfo', 'clientId'], data)
          this.dataForm['materPrice'] = this.R.pathOr(0, ['planOrderInfo', 'materialPrice'], data) == 0 ? undefined : this.R.pathOr(0, ['planOrderInfo', 'materialPrice'], data)
          this.dataForm['residueNumber'] =  this.R.pathOr(0, ['planOrderInfo', 'residueNumber'], data)*/
        })
      },
      weightSelectCallback(){
        const grossWeight = this.R.propOr(0, 'grossWeight', this.dataForm)
        const tareWeight = this.R.propOr(0, 'tareWeight', this.dataForm)
        this.dataForm.netWeight = grossWeight - tareWeight
      //  this.dataForm.amount = this.dataForm.materPrice * this.dataForm.netWeight
        this.dataForm.residueWeightCount = this.dataForm.residueNumber - this.dataForm.netWeight - this.dataForm.buckleWeight

      }

    }

  }
</script>

